<template>
  <div>
    <n-bar></n-bar>
    <van-form @submit="login">
      <van-field
        v-model="user.phone"
        name="手机号"
        label="手机号"
        placeholder="请输入手机号"
        :rules="[{required: true, message: '请输入正确的手机号' }]"
      />
      <van-field
        v-model="user.password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >登录</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import {Login} from '../request/app'
//引入轻提示
import {Toast} from 'vant'
export default {
  data() {
    return {
      user: {
        phone: "",
        password: "",
      },
    };
  },
  methods: {
    login() {
       Login(this.user)
       .then(res=>{
         if(res.code==200){
           Toast(res.msg)
          //  存储
          sessionStorage.setItem('userinfo',JSON.stringify(res.list))
          this.$router.push('/home')
        }else{
           Toast(res.msg)
         }
       })
    },
  },
};
</script>

<style scoped>
</style>
